﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace PMS.Controllers.BD
{
    public class PositionController : Controller
    {
        //
        // GET: /Position/

        public ActionResult PosList()
        {
            return View();
        }
        //获取岗位管理信息
        public void GetPositionList()
        {
            List<SearchCondition> listSearch = new List<SearchCondition>();
            if (Request.Form["searchData"] != null)
            {
                string searchData = Request.Form["searchData"];
                listSearch = ModelTools.GetSearchContions(searchData);
            }
            Expression<Func<View_BD_DepPosInfo, bool>> exp = SearchExpression.FindByGroup<View_BD_DepPosInfo>(listSearch);
            int count = 0;
            var list = BLLSession.Current.View_BD_DepPosInfoBLL.GetPagedList(OperateContext.Page, OperateContext.Rows, exp, u=>u.ID, OperateContext.Order);
            count = BLLSession.Current.View_BD_DepPosInfoBLL.GetCount(exp);
            Response.Write(JsonHelper.toPageJson(list, count));
        }
        //增加岗位管理信息
        public void AddPositionList()
        {
            BD_PosInfo per = new BD_PosInfo();
            ModelTools.Form2EditModel(Request.Form, per);
            per.FillDate = DateTime.Now.ToString("yyyy:MM:dd,HH:mm:ss");
            per.ManClerk = OperateContext.sessUserInfo.Name;
            BLLSession.Current.BD_PosInfoBLL.Add(per);
            Response.Write(JsonHelper.toDefaultMsg(true, "保存成功"));
        }
        //编辑岗位管理信息
        public void EditPositionList()
        {
            int Id = Commons.String2Int32(Request.Form["Id"]);
            BD_PosInfo perNew = DALSession.Current.BD_PosInfoDAL.GetListBy(d => d.ID == Id).FirstOrDefault();
            ModelTools.Form2EditModel(Request.Form, perNew);
            perNew.FillDate = DateTime.Now.ToString("yyyy:MM:dd,HH:mm:ss");
            perNew.ManClerk = OperateContext.sessUserInfo.Name;
            BLLSession.Current.BD_PosInfoBLL.ModifyAllModel(perNew);
            Response.Write(JsonHelper.toDefaultMsg(true, "保存成功"));
        }
        //获取岗位信息for combobox
        public void GetPosInfo()
        {
            Response.Write(JsonHelper.toJson(BLLSession.Current.BD_PosInfoBLL.GetListBy(p => p.PosState == "0").Select(p => new { value = p.ID, text = p.PosName })));
        }
    }
}
